package com.cskaoyan.day1.generic6;

/**
 * @author Common-zhou
 * @since 2023-02-27 15:01
 */
public class Generic4 {
    public static void main(String[] args) {
        User1<Integer> user = new User1<>();
        user.setData(10);

        Generic4 generic4 = new Generic4();


        //User1<Object>
        // User1<Integer>
        generic4.printUser(user);

        User1<String> user1 = new User1<>();
        user1.setData("hello java");
        generic4.printUser(user1);


    }

    /**
     * 允许接收所有类
     *
     * @param user
     */
    void printUser(User1<?> user) {
        System.out.println(user.data);
    }
}

class User1<T> {
    T data;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
